package org.xiji.composite;

import java.util.ArrayList;
import java.util.List;

public class Folder implements Component{
    /**
     * 定义一个集合，用来存储子组件
     */
    List<Component> childrenList = new ArrayList<>();
    protected String name;
    @Override
    public void add(Component component) {
        childrenList.add(component);

    }

    @Override
    public void remove(Component component) {
        childrenList.remove(component);

    }

    @Override
    public Component getChild(int index) {
        return childrenList.get(index);
    }

    /**
     * 文件夹操作
     */
    @Override
    public void operation() {
        System.out.println(name +"操作");
        System.out.println("============================");
        for (int i = 0; i < childrenList.size(); i++) {
            childrenList.get(i).operation();
        }
        System.out.println("============================");

    }
}
